package cn.iocoder.yudao.module.member.controller.app.userpromotionrecords;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
import cn.iocoder.yudao.module.member.controller.admin.userpromotionrecords.vo.UserPromotionRecordsRespVO;
import cn.iocoder.yudao.module.member.controller.app.userpromotionrecords.vo.AppUserPromotionRecordsStatisticsRespVO;
import cn.iocoder.yudao.module.member.controller.app.user.vo.AppMemberUserAddInvitationCodeReqVO;
import cn.iocoder.yudao.module.member.controller.app.userpromotionrecords.vo.AppUserPromotionRecordsPageReqVO;
import cn.iocoder.yudao.module.member.service.userpromotionrecords.UserPromotionRecordsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "APP（有关笔试） - 用户推广记录")
@RestController
@RequestMapping("/member/user-promotion-records")
@Validated
public class AppUserPromotionRecordsController {

    @Resource
    private UserPromotionRecordsService userPromotionRecordsService;

    @PutMapping("/add-invite-code")
    @Operation(summary = "添加邀请码")
    public CommonResult<Boolean> addInviteCode(@RequestBody @Valid AppMemberUserAddInvitationCodeReqVO reqVO) {
        userPromotionRecordsService.createUserPromotionRecords(WebFrameworkUtils.getLoginUserId(), reqVO.getInviteCode());
        return success(true);
    }

    @GetMapping("/page")
    @Operation(summary = "获得用户推广记录分页")
    public CommonResult<PageResult<UserPromotionRecordsRespVO>> getUserPromotionRecordsPage(@Valid AppUserPromotionRecordsPageReqVO pageReqVO) {
        pageReqVO.setInviterUserId(WebFrameworkUtils.getLoginUserId());
        return success(userPromotionRecordsService.getUserPromotionRecordsPageForApp(pageReqVO));
    }

    @GetMapping("/statistics")
    @Operation(summary = "获得推广记录统计")
    public CommonResult<AppUserPromotionRecordsStatisticsRespVO> getUserPromotionRecordsStatistics() {
        return success(userPromotionRecordsService.getUserPromotionRecordsStatistics(WebFrameworkUtils.getLoginUserId()));
    }

}